(function() {
  var ImportFiles, Utils, WaterfallsDataHandler, WebConfig, getButtonSetConfig, getComodityTags, viewContentHandler, _;

  _ = require('underscore');

  ImportFiles = require('../../../helpers/import_files');

  WebConfig = require('./web_config');

  WaterfallsDataHandler = require('../../../helpers/waterfalls_data_handler');

  Utils = require('../../../helpers/utils');

  viewContentHandler = {
    home: function(req, view, title, navIndex, commodities, pageConfig, selectedTag) {
      var itemFilter, pageButtonSetConfig, renderData, waterfallsDataHandler;
      _.each(commodities, function(item) {
        var _ref, _ref1;
        item.type = 'commodity';
        item.picUrl = ((_ref = item.pics) != null ? (_ref1 = _ref[0]) != null ? _ref1.url : void 0 : void 0) || '';
        return item.cutDesc = Utils.cutStringByViewSize(item.desc || item.title, 15 * 3);
      });
      waterfallsDataHandler = WaterfallsDataHandler.getWaterfallsDataHandler();
      itemFilter = {
        type: 'commodityFilter',
        tags: getComodityTags(),
        selectedTag: selectedTag
      };
      waterfallsDataHandler.add(itemFilter, 0, 510);
      waterfallsDataHandler.add(commodities);
      pageButtonSetConfig = getButtonSetConfig(pageConfig);
      renderData = {
        title: title || '',
        layout: 'ys/layout',
        importObj: ImportFiles.getImportObj(view),
        header: WebConfig.getHeader(navIndex || 0),
        viewContent: {
          waterfallsConfig: waterfallsDataHandler.getConfig(true),
          pageButtonSetConfig: pageButtonSetConfig
        }
      };
      return renderData;
    },
    commodity: function(req, view, title, navIndex, commodity) {
      var renderData, _ref, _ref1;
      commodity.picUrl = ((_ref = commodity.pics) != null ? (_ref1 = _ref[0]) != null ? _ref1.url : void 0 : void 0) || '';
      renderData = {
        title: title || '',
        layout: 'ys/layout',
        importObj: ImportFiles.getImportObj(view),
        header: WebConfig.getHeader(navIndex || 0),
        viewContent: {
          commodity: commodity
        }
      };
      return renderData;
    },
    commodityModify: function(req, view, title, navIndex, commodity) {
      var renderData, _ref, _ref1;
      commodity.picUrl = ((_ref = commodity.pics) != null ? (_ref1 = _ref[0]) != null ? _ref1.url : void 0 : void 0) || '';
      console.dir(commodity);
      renderData = {
        title: title || '',
        layout: 'ys/layout',
        importObj: ImportFiles.getImportObj(view),
        header: WebConfig.getHeader(navIndex || 0),
        viewContent: {
          commodity: commodity,
          allTags: getComodityTags()
        }
      };
      return renderData;
    },
    table: function(req, view, title, navIndex, tableData) {
      var renderData;
      renderData = {
        title: {
          title: '',
          layout: 'ys/layout'
        },
        importObj: ImportFiles.getImportObj(view),
        header: WebConfig.getHeader(navIndex || 0),
        viewContent: {
          tableData: tableData
        }
      };
      return renderData;
    }
  };

  getComodityTags = function() {
    var brands, categories, tags;
    brands = '箭牌 益达 劲浪 荷氏 维果C 曼妥思 阿尔卑斯 瑞士糖 百份百 趣满果 宝路 彩虹糖 雀巢 阿华田 桂格 立顿 元朗 金沙 好时 德芙 健逹 王老吉 波力 车仔 惠氏 美赞臣 多美滋 雅培 好立克 美禄 奥兰 能恩 子母 鹰唛 四洲 品客 百力滋 鹰牌 太古'.split(' ');
    categories = '口香糖 润喉糖 木糖醇 糖果 奶粉 麦片 咖啡 奶茶 茶 薯片 巧克力 威化 米粉 饮料 方糖'.split(' ');
    tags = [];
    _.each(brands, function(brand) {
      return tags.push({
        name: brand
      });
    });
    _.each(categories, function(category) {
      return tags.push({
        name: category
      });
    });
    return tags;
  };

  getButtonSetConfig = function(pageConfig) {
    var eachPageTotal, end, pageButtonSetConfig, start, total;
    start = pageConfig.currentPage || 1;
    eachPageTotal = pageConfig.eachPageTotal || 1;
    total = pageConfig.total || 1;
    end = Math.ceil(total / eachPageTotal);
    if (start === end) {
      return null;
    }
    pageButtonSetConfig = {
      start: start,
      end: end,
      total: 10
    };
    return pageButtonSetConfig;
  };

  module.exports = viewContentHandler;

}).call(this);
